package main

import (
	"encoding/json"
	"fmt"
)

type Movie struct {
	Title  string   `json:"title"`
	Year   int      `json:"year"`
	Price  int      `json:"price"`
	Actors []string `json:"actors"`
}

func main() {
	movie := Movie{
		"喜剧之王",
		2000,
		10,
		[]string{
			"周星驰",
			"张柏芝",
		},
	}
	//转json
	josnStr, err := json.Marshal(movie)
	if err != nil {
		fmt.Println("json marshal error:", err)
		return
	}
	fmt.Printf("%s\n", josnStr)
	//json转结构体
	jsonMovie := Movie{}
	err = json.Unmarshal(josnStr, &jsonMovie)
	if err != nil {
		fmt.Println("json unmarshal err:", err)
		return
	}

	fmt.Printf("%v\n", jsonMovie)
}
